package utils;

import android.text.TextUtils;

import java.util.ArrayList;
import java.util.List;

import topic.bean.TopicGroupBean;

/**
 * Created by Administrator on 2017/3/21.
 */

public class VariousUtils_Delete {
    public static TopicGroupBean.BlogListBean noHttps(TopicGroupBean.BlogListBean bean) {
        //TODO
        // 如果https好了就要删掉这个方法
        String headimgurl = bean.getHeadimgurl();
        if (!TextUtils.isEmpty(headimgurl)) {
            String newUrl = headimgurl.split("https")[0];
            newUrl = "http" + newUrl;
            bean.setHeadimgurl(newUrl);
        }
        List<String> images = bean.getImages();
        List<String> images2 = new ArrayList<>();
        if (images.size() > 0) {
            for (int i = 0; i < images.size(); i++) {
                String s = images.get(i);
                if (s.contains("https")) {
                    String newUrl = "http:" + s.split(":")[1];
                    images2.add(newUrl);
                } else {
                    images2.add(s);
                }
            }
            bean.setImages(images2);
        }
        return bean;
    }

    public static List<TopicGroupBean.TopicListBean> noHttps(List<TopicGroupBean.TopicListBean> topicList) {
        List<TopicGroupBean.TopicListBean> images = new ArrayList<>();
        if (topicList!=null) {
            if (topicList.size() > 0) {
                for (int i = 0; i < topicList.size(); i++) {
                    TopicGroupBean.TopicListBean topicListBean = topicList.get(i);
                    String image = topicListBean.getImage();
                    String newUrl = image.split("https")[0];
                    if (!newUrl.contains("http")) {
                        newUrl = "http" + newUrl;
                    }
                    topicListBean.setImage(newUrl);
                    images.add(topicListBean);
                }
            }
        }
        return images;
    }

    public static String noHttps(String value){
        String newValue = value ;
        if(value.contains("https")){
            String[] httpses = value.split("https");
            String httpse = httpses[1];
            newValue = "http"+ httpse;
        }
        return newValue;
    }
}
